package com.chuangmei.com.arindoorlocationsystem.ar;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;

import java.util.ArrayList;
import java.util.List;

/**
 * 项目名称：ARIndoorLocationSystem
 * 类描述：AR权限管理
 * 创建人：LuoHao
 * 创建时间：2018/4/16 17:47
 * 修改人：LuoHao
 * 修改时间：2018/4/16 17:47
 * 修改备注：
 */

public class ARPermissionManage {

    private static final int RECORD_REQUEST_CODE = 101;
    private static final int STORAGE_REQUEST_CODE = 102;
    private static final int AUDIO_REQUEST_CODE = 103;
    private final Context context;

    public ARPermissionManage(Context context) {
        this.context = context;
    }


    /**
     * 初始化权限
     */
    protected void initPermission() {
        List<String> list = new ArrayList<>();
        int i = 0;
        if (ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager
                .PERMISSION_GRANTED) {
            list.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
            i++;
            //            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission
            // .WRITE_EXTERNAL_STORAGE}, 102);
        }
        //自动录音
        if (ContextCompat.checkSelfPermission(context, Manifest.permission.RECORD_AUDIO) != PackageManager
                .PERMISSION_GRANTED) {
            list.add(Manifest.permission.RECORD_AUDIO);
            i++;
            //            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.RECORD_AUDIO}, 103);
        }
        //相机权限
        if (ContextCompat.checkSelfPermission(context, Manifest.permission.CAMERA) != PackageManager
                .PERMISSION_GRANTED) {
            list.add(Manifest.permission.CAMERA);
            i++;
            //            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, 104);
        }
        if (i > 0) {
            String[] strings = list.toArray(new String[i]);
            ActivityCompat.requestPermissions((ARStudyActivity) context, strings, RECORD_REQUEST_CODE);
        }
    }
}
